package com.zhiwei.controller;

import com.zhiwei.pojo.Products;
import com.zhiwei.pojo.Trader;
import com.zhiwei.service.TraderService;
import com.zhiwei.vo.PageResult;
import com.zhiwei.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/trader")
public class TraderController {
    @Autowired
    private TraderService traderService;
    @GetMapping("/allList")
    public SysResult getTraderLists(){
        List<Trader> traders = traderService.getTraderLists();
        return SysResult.success(traders);
    }

    @GetMapping("/list")
    public SysResult getTraders(PageResult pageResult){
        PageResult traders = traderService.getTraders(pageResult);
        return SysResult.success(traders);
    }
    @PutMapping("/update")
    public SysResult updateTrader(@RequestBody Trader trader){
        traderService.updateTrader(trader);
        return new SysResult();
    }
    @DeleteMapping("/deleteTrader/{id}")
    public SysResult deleteTrader(@PathVariable Integer id){
        traderService.deleteTrader(id);
        return SysResult.success();
    }
    @PostMapping("/insertTrader")
    public SysResult insertTrader(@RequestBody Trader trader){
        traderService.insertTrader(trader);
        return SysResult.success();

    }
}
